package com.design.observer;

import java.util.ArrayList;
import java.util.List;

public class WechatServer implements Observerable{
	private List<Observer> list;
	private String message;
	
	public WechatServer() {
		list = new ArrayList<Observer>();
	}

	@Override
	public void registerObserver(Observer o) {
		list.add(o);
	}

	@Override
	public void removeObserver(Observer o) {
		list.remove(o);
	}

	@Override
	public void notifyObserver() {
		if(list != null && list.size() > 0) {
			for(Observer o : list) {
				o.update(message);
			}
		}
	}

	public void setMessage(String message) {
		this.message = message;
		System.out.println("WeChat update Message:" + message);
		notifyObserver();
	}

	
}
